package it.asvp.asvp_portal.data.dao.impl;


import it.asvp.asvp_portal.data.dao.NotificationReceiverDao;
import it.asvp.asvp_portal.data.entity.notification.NotificationReceiver;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Repository;

@Repository
public class NotificationReceiverDaoImpl implements NotificationReceiverDao{

	private static final Log log = LogFactory.getLog(NotificationReceiverDaoImpl.class);

	@Autowired
	SessionFactory sessionFactory;

	public void persist(NotificationReceiver transientInstance) {
		log.debug("persisting NotificationReceiver instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}


	public void delete(NotificationReceiver persistentInstance) {
		log.debug("deleting NotificationReceiver instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public NotificationReceiver merge(NotificationReceiver detachedInstance) {
		log.debug("merging NotificationReceiver instance");
		try {
			NotificationReceiver result = (NotificationReceiver) sessionFactory
					.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public NotificationReceiver findById(java.lang.Long id) {
		log.debug("getting NotificationReceiver instance with id: " + id);
		try {
			NotificationReceiver instance = (NotificationReceiver) sessionFactory
					.getCurrentSession()
					.get("it.asvp.asvp_portal.data.dao.generator.NotificationReceiver",
							id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

}
